using System;


/// <summary>
/// Summary description for HitCounter
/// </summary>
public partial class RecruitVietnam
{

    #region Site HitCounter
    public void WriteHitCounterToDatabase(long hitCounter)
	{
        try
        {
            SqlServerProvider sqlServerProvider
           = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText =
            "Update tblHitCounter set " +
            "HitCounter=@HitCounter" + 
            ",LastUpdate=getdate() " +
            " where Name='Site'";
           sqlServerProvider.ParameterCollection =
           new string[1] { "@HitCounter" };
           sqlServerProvider.ValueCollection =
           new string[1] { hitCounter.ToString() };  
           sqlServerProvider.ExecuteNonQuery();
           sqlServerProvider.CloseConnection();          
        }
        catch (Exception ex)
        {
            errorMessage= ex.Message;
        }
	}
	
    public int ReadHitCounterFromDatabase()
    {
        int hitCounter=0;
        try
        {
            SqlServerProvider sqlServerProvider
           = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText =
            "select HitCounter from  " +
            " tblHitCounter " +
            " where Name='Site'";            
            sqlServerProvider.ExecuteNonQuery();
            sqlServerProvider.CloseConnection();               
        }
        catch (Exception ex)
        {
            hitCounter=1000;
            errorMessage=ex.Message;
        }
        return hitCounter;
    }
    #endregion

    #region Page HitCounter
    public void WritePageHitCounterToDatabase(
    string pageHitCounter, string jobSeekerModule)
    {
        try
        {
            SqlServerProvider sqlServerProvider
           = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText =
            "Update tblHitCounter set " +
            "HitCounter = HitCounter + 1," +
            "Type = @Type, " +
            "LastUpdate=getdate() " +
            " where Name=@PageHitCounter";
            sqlServerProvider.ParameterCollection =
            new string[2] {"@PageHitCounter", "@Type"};
            sqlServerProvider.ValueCollection =
            new string[2] {pageHitCounter, "0"};
            sqlServerProvider.ExecuteNonQuery();
            sqlServerProvider.CloseConnection();
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
        }
    }    
    #endregion
    
} 
